import { fetchCouponList } from '../../../services/coupon/index';
import { api } from '../../../config/api';
import { request } from '../../../utils/request';

Page({
	data: {
		status: 0,
		list: [
			{
				text: '全部',
				key: 0,
			},
			{
				text: '可领取',
				key: 1,
			}
		],
		couponList: []
	},

	onLoad() {
		this.init();
	},

	init() {
		this.fetchList();
	},

	fetchList() {
		request.get(api.coupon.query, { page: 1, pageSize: 20, type: this.data.status })
			.then((couponList) => {
				this.setData({ couponList });
			});
	},
	goCouponCenterHandle() {
		wx.navigateTo({ url: '/pages/goods/list/index' });
	},
	tabChange(e) {
		const { value } = e.detail;

		this.setData({ status: value });
		this.fetchList();
	},
});
